package net.playcabbage.utility;

public class CabbageStringsUtility {

	public static String stripURLString(String urlString) {

		return null;
	}

	// Checks the given string is the given length.
	public static boolean correctLength(String string, int len) {//
		if (string == null) return false;

		if (string.length() != len) return false;
		return true;
	}

	// Checks that the numbers contained in a string are within a given range.
	public static boolean isInBounds(String string, int min, int max) { //
		if (string == null) return false;
		if (!(isNumeric(string))) return false;

		int num = Integer.parseInt(string);
		if (! (num >= min && num <= max)) return false;
		return true;
	}

	// Checks that the numbers contained in a Z string parameter are within a given range.
	// A valid z parameter can be 00 or have a 0 on the left or right - 
	// but cannot contain non zeros on both sides.
	public  static boolean isValidZParameter(String string, int min, int max) {

		if (string == null) return false;
		if (!(isNumeric(string))) return false;
		if (!(correctLength(string,2))) return false;

		char str1 = string.charAt(0);
		char str2 = string.charAt(1);

		int num1 = Character.getNumericValue(str1);
		int num2 = Character.getNumericValue(str2);

		//if(num1 > 0 && num2 > 0) return false;

		if (num1 == num2) {
			if (num1 != 0) return false;
		}

		if (!(num1 >= min & num1 <= max)) return false;
		if (!(num2 >= min & num2 <= max)) return false;

		return true;
	}

	// Checks a given string is numeric.
	public static boolean isNumeric(String string) { //
		if (string == null) return false;

		for (char c : string.toCharArray()) {
			if (!Character.isDigit(c)) return false;
		}
		return true;
	}

	// Checks that two chars are the same.
	public static boolean isCharacter(char c1, char c2) {//
		if (c1 == 0) return false;
		if (c2 == 0) return false;

		if (c1 != c2) return false;
		return true;
	}

}
